cmake_minimum_required(VERSION 3.22)
project(cmake_hello)

set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 20)

find_package(glog CONFIG COMPONENTS glog REQUIRED)
find_package(gflags CONFIG REQUIRED)

find_package(CapnProto CONFIG REQUIRED)
find_package(civetweb CONFIG REQUIRED)

add_subdirectory(common)

include(cmake/capnproto.cmake)
generate_capn_proto("addressbook" "calculator")

add_executable(addressbook
        addressbook.cc
)

target_link_libraries(addressbook
        CapnProto::capnp
        #        CapnProto::capnp-rpc
        #        CapnProto::capnp-json
        #        CapnProto::kj
        #        CapnProto::kj-async
        #        CapnProto::kj-http
        #        CapnProto::kj-tls
        #        CapnProto::kj-gzip
        log
        capn_addressbook
)


add_executable(calculator-server
        calculator-server.cc
        calculator-server.h
)

target_link_libraries(calculator-server PRIVATE
        log
        capn_calculator
)

# project cmake_hello
add_executable(${PROJECT_NAME}
        main.cpp
        #        civetweb_server.cpp
)

# because most shared libraries use libstdc++, so even if we use libc++, we still need to link to libstdc++
#set(USED_STDLIB "libc++")
#set(USED_STDLIB "libstdc++")

target_link_libraries(${PROJECT_NAME}
        log
        #        civetweb::civetweb-cpp
)

#target_compile_options(${PROJECT_NAME} PRIVATE
#        -Wall -stdlib=${USED_STDLIB}
#)

#target_link_options(${PROJECT_NAME} PRIVATE
#        #       the following two options only support clang, and must be added also in compile options
#        -stdlib=${USED_STDLIB}
#        #         https://gcc.gnu.org/onlinedocs/gcc-12.3.0/gcc/Link-Options.html#index-static
#        #        -static-libgcc
#        #        -static-libstdc++
#        #        -static
#        -fuse-ld=lld
#)

set(CMAKE_CXX_STANDARD 20)
add_executable(test_cv
    test_cv.cc
)

add_subdirectory(tests)
# ctest --build-run-dir cmake-build-debug/tests --test-dir cmake-build-debug/tests

# clang++ -Wall -I/usr/include/c++/11 -I/usr/include/x86_64-linux-gnu/c++/11 -L /usr/lib/gcc/x86_64-linux-gnu/11 -o h hello.cc
# clang++ -fuse-ld=gold -Wall -o h hello.cc

# sudo apt install libc++-15-dev libc++abi-15-dev libstdc++-12-dev

add_executable(omx_test
    omx_test.cc
        app_context.cpp
        app_context.h

        omx_callback_base.cc
        omx_callback_base.h
)

# use omxregister-bellagio -vl to see all the registered components
find_package(PkgConfig REQUIRED)
set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:$ENV{HOME}/Downloads/libomxil-bellagio/build/install/lib/pkgconfig")
pkg_check_modules(libomxil REQUIRED IMPORTED_TARGET libomxil-bellagio)

add_library(enum2string STATIC
        enum_to_string_helper.h
        enum_to_string.h
        enum_to_string.cc
)


target_link_libraries(enum2string
        log
        PkgConfig::libomxil
)

pkg_check_modules(readline REQUIRED IMPORTED_TARGET readline)

target_link_libraries(omx_test
        log
        PkgConfig::libomxil
        enum2string
#        PkgConfig::readline
)